package com.frikinet.lifeguard.tests;

import java.net.URL;

import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathFactory;

import org.lobobrowser.html.UserAgentContext;
import org.lobobrowser.html.parser.DocumentBuilderImpl;
import org.lobobrowser.html.parser.InputSourceImpl;
import org.lobobrowser.html.test.SimpleUserAgentContext;
import org.w3c.dom.Document;

public class ParseFotologTest
{
	public static void main(String args[]) throws Exception
	{
		// Disable most Cobra logging.
        //Logger.getLogger("org.lobobrowser").setLevel(Level.WARNING);
        
		UserAgentContext uaContext = new LocalUserAgentContext();
		DocumentBuilderImpl builder = new DocumentBuilderImpl(uaContext);
		
		//Open URL
		URL url = new URL("http://www.fotolog.com/kitsunebi/archive");
		InputSourceImpl input = new InputSourceImpl(url.openStream(), url.toString(), "ISO-8859-1");
		Document doc = builder.parse(input);
		//HtmlParser parser = new HtmlParser(uaContext, doc);
		//parser.parse(new InputStreamReader(url.openStream(), "ISO-8859-1"));
		
		XPath xpath = XPathFactory.newInstance().newXPath();
		Object o = xpath.evaluate("//div[@id='years']", doc, XPathConstants.NODE);
		System.out.println(o);
	}
	
	private static class LocalUserAgentContext extends SimpleUserAgentContext
	{
		@Override
		public boolean isScriptingEnabled()
		{
			return false;
		}

		@Override
		public boolean isExternalCSSEnabled()
		{
			return false;
		}

		@Override
		public String getUserAgent() {
			return "Mozilla/4.0 (compatible; MSIE 6.0;) Cobra/ScrapingTest Parser Demo";
		}
	}
}
